package cn.dengta.webapp.user.vo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import javax.annotation.Nullable;

import cn.dengta.common.model.APIResponse.Field;
import cn.dengta.common.model.Status;
import cn.dengta.common.util.Formats;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.user.dto.PrizeLogDTO;
import cn.dengta.webapp.user.entity.PrizeLog;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.Cmp;
import me.codeplayer.util.CollectionUtil;

@Getter
@Setter
public class PrizeLogVO extends AbstractVO<PrizeLog> {

	@Field("用户")
	public Map<String, Object> user;
	@Field("发送人")
	public Map<String, Object> sendUser;
	@Field("活动")
	public Map<String, Object> activity;
	@Field("奖品")
	public Map<String, Object> prize;
	@Field("发放状态")
	protected Integer status;
	@Field("是否可发放")
	protected Boolean canSend;
	@Field("发放时间")
	private transient Date sendTime;
	/** 名称 */
	protected String name;
	/** 图片 */
	protected String icon;
	/** 数量 */
	protected Integer count;
	/** 价值 */
	protected Integer amount;
	/** 备注 */
	private String remark;
	/** 交易额度 */
	protected transient BigDecimal tradeAmount;
	/** 本次交易使用的免费钻石 */
	protected transient BigDecimal tradeFreePart;

	public static PrizeLogVO from(@Nullable PrizeLog source) {
		return copy(source, PrizeLogVO::new);
	}

	public static PrizeLogVO from(@Nullable PrizeLogDTO source) {
		PrizeLogVO vo = copy(source, PrizeLogVO::new);
		if (vo != null) {
			if (source.getActivityId() != null) {
				vo.setActivity(CollectionUtil.ofHashMap("id", source.getActivityId(), "name", source.getActivityName()));
			}
			if (source.getPrizeId() != null) {
				vo.setPrize(CollectionUtil.ofHashMap("id", source.getPrizeId(), "name", source.getPrizeName()));
			}
		}
		return vo;
	}

	public String getStatus_() {
		return status != null ? (Status.asResult(status) ? "已发放" : "待发放") : null;
	}

	public String getSendTime_() {
		return Formats.formatDefDate(sendTime);
	}

	public String getAmount_() {
		return Formats.formatNumber_D(amount);
	}

	public String getTradeAmount_() {
		return Formats.formatNumber_D(tradeAmount);
	}

	public String getTradeFreePart_() {
		return Formats.formatNumber_D(tradeFreePart);
	}

	public String getTradeRecharge_() {
		return Formats.formatNumber_D(Cmp.nullToZero(tradeAmount).subtract(Cmp.nullToZero(tradeFreePart)));
	}

	public String getAddTime_() {
		return super.getAddTime_();
	}

}
